import { db } from '../db/index'
import { Model, DataTypes } from 'sequelize'
import Role from './Role'
import UserInfo from './UserInfo'
class Admin extends Model {
  public id!: number
  public username!: string
  public password!: string
  public phone!: number
  public avatar!: string
  public role_id!: number
}

Admin.init({
  id: {
    type: DataTypes.INTEGER,
    allowNull: false,
    autoIncrement: true,
    primaryKey: true
},
username: {
    type: DataTypes.STRING,
    allowNull: false
},
password: {
    type: DataTypes.STRING,
    allowNull: false
},
phone: {
    type: DataTypes.BIGINT,
    allowNull: false
},
avatar: {
    type: DataTypes.STRING,
    allowNull: false
},
role_id: {
    type: DataTypes.INTEGER,
    allowNull: false
}
}, {
  tableName: 'admins',
  modelName: 'admin',
  sequelize: db
});

// 创建 user 表
// Admin.sync({ force: true })
Admin.hasMany(UserInfo, {as: 'userinfo', foreignKey: 'a_id' })
Admin.belongsTo(Role, {foreignKey: 'role_id'});
export default Admin
